package com.dataseek.iot.core.util;

import lombok.Getter;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;
import org.thymeleaf.spring5.context.webflux.SpringWebFluxContext;

/**
 * @author cc
 * @Title: ApplicationContextUtil
 * @Description: 手动获取bean的工具类
 * @date 2021/9/299:01 下午
 * @since 1.0
 */
@Component
public class ApplicationContextUtil implements ApplicationContextAware {

    private static ApplicationContext context;


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context  = applicationContext;
    }

    /**
     * 获取bean名称
     * @param beanName
     * @return
     */
    public static Object getBean(String beanName){
        return context.getBean(beanName);
    }
}
